
package com.project.config;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

    public class MyLoginFilter implements Filter {
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest hreq=(HttpServletRequest)request;
        String token = hreq.getHeader("token");
        System.out.println("token"+token);
        HttpServletResponse resp = (HttpServletResponse) response;
        if(token!=null||hreq.getServletPath().equals("/login.do")||hreq.getMethod().equals("OPTIONS")){
            System.out.println("放行");
            chain.doFilter(request,response);
        }
        else {
            System.out.println("不放行");
            response.setContentType("text/html;charset=utf-8");
            response.getWriter().print("没有权限");
        }
    }
}
